<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/7/10 0010
 * Time: 17:12
 */
namespace App\FreeBird\Models;
use App\Admin\Models\MemberModel;
use App\Admin\Models\UcenterMemberModel;
use App\Base\Models\BaseModel;
use App\Weixin\Models\WeixinUserModel;
use Illuminate\Database\Eloquent\SoftDeletes;

class CustomerServiceModel extends  BaseModel {
    use SoftDeletes;
    /**
     * 表名
     * @var string
     */
    public $table="freebird_customer_service";
    /**
     * 时间自动
     * @var bool
     */
    public $timestamps=true;
    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    const CREATED_AT = 'create_time';  //修改添加时间字段
    /**
     * The name of the "updated at" column.
     *
     * @var string
     */
    const UPDATED_AT = 'update_time';

    /**
     * 删除
     */
    const DELETED_AT = 'delete_time';
    /**
     * 模型的日期字段保存格式。
     */
    protected $dateFormat = 'U';

    //拼上手机号与姓名
    protected $appends = ["username", "mobile"];


    /**
     * 获取用户模块
     * @return MemberModel
     */
    public function getMemberModel(){
        return app()->make(MemberModel::class);
    }

    /**
     * 获取用户模块
     * @return UcenterMemberModel
     */
    public function getUcenterMemberModel(){
        return app()->make(UcenterMemberModel::class);
    }

    /**
     * 微信用户模块
     * @return WeixinUserModel
     */
    public function getWeixinUserModel(){
        return app()->make(WeixinUserModel::class);
    }

//    /**
//     * 用户名称
//     * @return \Illuminate\Database\Eloquent\Relations\HasOne
//     */
    public function weixinuser(){
        return $this->hasOne(WeixinUserModel::class,"uid","uid");
    }

    /**
     * 省份 名称
     * @return string
     */
    public function getUsernameAttribute(){
        $uid=$this->uid;
        $info=$this->getWeixinUserModel()->newQuery()->where("uid",$uid)->first();
        return $info["truename"] ?? '';
    }

    /**
     * 省份 名称
     * @return string
     */
    public function getMobileAttribute(){
        $uid=$this->uid;
        $info=$this->getUcenterMemberModel()->newQuery()->where("id",$uid)->first();
        return $info["mobile"] ?? '';
    }
}